package leetcode_top;
import java.util.*;
import org.junit.*;
public class Ex204 {
    class Solution {
        public int countPrimes(int n) {
            boolean[] f = new boolean[n + 1];
            Arrays.fill(f, true);
            int max = (int)Math.sqrt(n), t, j;
            f[0] = false;
            f[1] = false;
            for (int i = 2; i <= max; i++) {
                j = 2;
                while ((t = j * i) <= n) {
                    f[t] = false;
                    j++;
                }
            }
            int cnt = 0;
            for (int i = 2; i < n; i++) {
                if (f[i]) cnt++;
            }
            return cnt;
        }
    }

    @Test
    public void test() {
        Solution s = new Solution();
        // System.out.println(s.countPrimes(100));    
        System.out.println(s.countPrimes(10));        

    }
}
